home *** CD-ROM | disk | FTP | other *** search
/ Sun Solutions 1997 April to September / Sun Solutions CD - APR '97 - SEP '97 (704-3778-12 Rev. H)(Sun Microsystems, Inc.)(1997).iso / products / .wais / Solaris_2 / test.pl < prev    next >
Perl Script  |  1995-12-11  |  10KB  |  452 lines

  1. #!/net/pinatubo/opt/PUBperl5/bin/perl5
  2. # /export/scratch/illustra/bin/perl5
  3. # /opt/PUBperl5/bin/perl5
  4. #
  5. # makedesc.pl
  6. #
  7. # Generate The Wais Tree
  8. #
  9. # Copyright Creative Dynamics, Inc. 1995
  10. #
  11. #$dirn = $0;
  12. #$dirn =~ s#(.*)/.*$#$1#;
  13. #require "$dirn/common.pl";
  14.  
  15. $CATDB_NAME = "catalyst";
  16. $USER = "miadmin";
  17. $HOST = "localhost:7999";
  18. $HTML = "index.html";
  19.  
  20. #
  21. # use the libmi stuff
  22. #
  23.  
  24. use Mi;
  25.  
  26. $lastCategory = "";
  27. $lastSubCategory = "";
  28. $newchapter = 0;
  29.  
  30. ### Set up output directory
  31.  
  32. $outputDirectory = "/cdware/SPARC/.products/.wais/wais-src";
  33. umask(022);
  34. mkdir($outputDirectory, 0777);        # make an output directory for book    
  35. chdir "$outputDirectory" || die "Can't cd to $outputDirectory\n";
  36. unlink(<*>);                # delete all existing files in the output directory
  37.  
  38. {
  39.    local($query,$num_col, @record);
  40.    local($db, $row_desc, $result, $row, $col, $row_num, $error);
  41.  
  42. ### the query
  43.  
  44. $query = "
  45. select  p.Product_id, p.SolCompatible,    
  46.     p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName,
  47.     p.ProdShortDesc, p.ProdLongDesc,
  48.     p.ProdHomePage, p.ProdImage, p.SrcAvail, p.ProdSrcLang,
  49.     p.ProdSpecHand,
  50.     v.VendorAddr1, v.VendorAddr2, v.VendorAddr3, v.VendorCity,
  51.     v.VendorPostCode,
  52.     v.VendorState, v.VendorZip, v.VendorCountry,
  53.     v.VendorPhone1code, v.VendorPhone1,
  54.     v.VendorPhone2code, v.VendorPhone2,
  55.     v.VendorFaxCode, v.VendorFax,
  56.     v.VendorEmailCode, v.VendorEmail,
  57.     v.VendorURL
  58. from   Vendor v using(lock=table),
  59.        Assoc_ProdVend a using(lock=table),
  60.        Products p using(lock=table)
  61. where  a.ProdId = p.Product_id
  62. and    a.VendId = v.Vendor_id
  63. order by p.ProdCatName, p.ProdSubCat, p.ProdName
  64. ;";
  65.  
  66. # where  p.Product_id < 100 -- use to limit
  67. # alternate order: order by p.ProdCatName, p.ProdSubCat, p.ProdName, v.VendorName
  68.  
  69. ### query the database
  70.  
  71.    ($db = Mi::open("$CATDB_NAME", "$USER", "") ) || die "Can't open Illustra database\n";
  72.  
  73.    (Mi::exec($db, "$query", 0) == 0) || die "Can't exec Illustra query\n";
  74.  
  75.    print "  Query Sent\n";
  76.  
  77.    (($result = Mi::get_result($db)) == 1) || die "Got bad result from Illustra\n";
  78.  
  79.    print "  Got Results\n";
  80.  
  81.    ($row_desc = Mi::get_row_desc_without_row($db)) || die "Error on row description \n";
  82.  
  83.    $num_col = Mi::column_count($row_desc);
  84.  
  85.    print "  Results Have $num_col Columns\n";
  86.  
  87.    $row_num = 0;
  88.    while ($row = Mi::next_row($db, \$error))
  89.    {
  90.     $row_num++;
  91.     print "   Processing row $row_num...\r";
  92.     foreach $col (0..$num_col-1)
  93.     {
  94.           Mi::value($row, $col, $colval, $retlen);
  95.           $record[$col] = $colval;
  96.     }
  97.  
  98. ### Fix the data
  99.  
  100. # map double occurrences of ' to single '
  101.  
  102.     foreach $count (2..12)
  103.     {
  104.         $record[$count] =~ s/\'\'/\'/g;
  105.     }
  106.  
  107. ### Trim trailing spaces
  108.     foreach $count (2..30)
  109.     {
  110.         $record[$count] =~ s/ *$//g;
  111.     }
  112.  
  113. ### Fix descriptions
  114.     $record[7] = ($record[7] =~ /\S/) ? $record[7] : $record[6];
  115.         if ($record[7] eq "")
  116.         {
  117.                 $record[7] = $record[6];
  118.         }
  119.         &makeBullets();
  120.  
  121. ### Now print out the data for this product        
  122.  
  123.     $newchapter = 0;
  124.     if ($lastCategory ne $record[2])
  125.     {
  126.         chdir $outputdirectory || die "bad cd\n";
  127.         $newchapter = 1;
  128.         $outputChapterName = &fix_special($record[2]);
  129.         $outputChapterName = &makefilename($outputChapterName, 25);
  130.         mkdir($outputChapterName, 0777);
  131.         chdir "$outputChapterName" || die "Can't cd to $outputChapterName\n";
  132.         unlink(<*>);
  133.         $lastCategory = $record[2];
  134.                 $subTOCname = $outputChapterName . ".html";
  135.                 open(subTOC, "> $subTOCname");
  136.                 &addsubTOCheader($record[2]);
  137.     }
  138.     if ($lastSubCategory ne $record[3])
  139.     {
  140.         if ($record[3] eq "")
  141.         {
  142.             $record[3] = "NoSubcategory";
  143.         }
  144.         if ($newchapter == 0)
  145.         {
  146.             chdir ".." || die "bad sub cd\n";
  147.         }
  148.         $outputSubchapterName = &fix_special($record[3]);
  149.         $outputSubchapterName = &makefilename($outputSubchapterName, 25);
  150.         mkdir($outputSubchapterName, 0777);
  151.         chdir $outputSubchapterName || die "Can't cd to $outputSubchapterName\n";
  152.         unlink(<*>);
  153.         $lastSubCategory = $record[3];
  154.                 $TOCname = $outputSubchapterName . ".html";
  155.                 open(TOC, "> $TOCname");
  156.                 &makeTOCheader($subTOCname, $record[2], $record[3]);
  157.                 chdir("..") || die "Can't cd to main category";
  158.                 &addsubTOC($record[3], $outputSubchapterName);
  159.                 chdir "$outputSubchapterName" || die "Can't cd to subcategory";
  160.     }
  161.  
  162.     $filename = &fix_special($record[4]);
  163.     $filename = &makefilename($filename, 25);
  164.     $filename .= ".html";
  165.     open(PRODUCT, ">$filename") || die "Can't open product $filename\n";
  166.         &makeproductheader($record[3], $outputChapterName . ".html");
  167.         &makeproduct();
  168.         &makeproducttail();
  169.         &addTOCinfo($filename, $record[4], $record[5]);
  170.         close PRODUCT;
  171.  
  172.     }
  173.  
  174.  
  175. # End of Product
  176.  
  177.    &makeTOCtail();
  178.    close TOC;
  179.    close subTOC;
  180.    Mi::close($db);
  181.  
  182.    print "Processed $row_num records\n";
  183. }
  184.  
  185.  
  186. #------------------------------------------------------------------
  187. # SUBROUTINES
  188. #------------------------------------------------------------------
  189.  
  190. sub makeBullets {
  191.  
  192.     local(@strings) = split(/\n/, $record[7]); 
  193.     local($bullet) = 0; 
  194.  
  195.     foreach $string (@strings)
  196.     {
  197.     if ($string =~ s/^--/<LI>/)
  198.     {
  199.         if ($bullet == 0)
  200.         {
  201.         $string =~ s/<LI>/<UL><LI>/;    
  202.         $bullet = 1;
  203.         }
  204.     }
  205.     else
  206.     {
  207.         if ($bullet == 1)
  208.         {
  209.         $string = "</UL>" . $string;
  210.         $bullet = 0;
  211.         }
  212.     }
  213.     }
  214.     $record[7] = join(/\n/, @strings);
  215.     if ($bullet == 1) # check for corner case
  216.     {
  217.          $record[7] .= "</UL>";
  218.     }
  219. }
  220.  
  221. sub makefilename {
  222.  
  223.         local(@strings) = split(/_/, @_[0]);
  224.     local($length) = @_[1];
  225.         local($new) = "";
  226.     local($first) = 1;
  227.  
  228.     foreach $string (@strings)
  229.     {
  230.     if ($first == 1)
  231.     {
  232.         $new .= $string;
  233.         $first = 0;
  234.     }
  235.     else
  236.     {
  237.         $new .= "_" . $string;
  238.     }
  239.     if (length($new) > $length)
  240.     {
  241.         return $new;
  242.     }
  243.     }
  244.     return $new;
  245. }
  246.  
  247. sub fix_special {
  248.  
  249.     local($text) = @_[0];
  250.  
  251.     $text =~ s/ /_/g;
  252.     $text =~ s/\!/_/g;
  253.     $text =~ s/\*/_/g;
  254.     $text =~ s/\//_/g;
  255.     $text =~ s/\&/_/g;
  256.     $text =~ s/\'/_/g;
  257.     $text =~ s/\`/_/g;
  258.     $text =~ s/#//g;
  259.     return $text;
  260. }
  261.  
  262. #------------------------------------------------------------------
  263. # makeproductheader
  264. #
  265. # subroutine makeproductheader creates header for every product file
  266.  
  267. sub makeproductheader {
  268.  
  269.     local($string) = @_[0];
  270.     local($filename) = @_[1];
  271.  
  272.     print PRODUCT <<PRODUCTHEADER;
  273. <html>
  274. <head>
  275. <title>Solaris - $string</title>
  276. </head>
  277. <body>
  278. <A HREF="http://$HOST/$HTML"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page</A> <A HREF=../$filename><IMG SRC="/goto_back.gif"> Sub-category</A>
  279. <HR>
  280. <H2><A NAME=$record[3]>"$record[3]"</A></H2>
  281.  
  282. <HR>
  283. PRODUCTHEADER
  284. }
  285.  
  286. #------------------------------------------------------------------
  287. # makeproduct
  288. #
  289. # subroutine makeproduct creates info for every product file
  290.  
  291. sub makeproduct {
  292.  
  293.     local($source) = "No";
  294.     local($address) = $record[13] . " " . $record[14] . " " . $record[15];
  295.     local($address1) = $record[16] . ", " . $record[17] . $record[18] . " " . $record[19];
  296.     local($spec) = $record[12];
  297.     local($phone) = "";
  298.     local($phone1) = "";
  299.     local($fax) = "";
  300.     local($email) = "";
  301.     local($url) = "";
  302.     local($language) = "";
  303.     if ($record[11] ne "")
  304.     {
  305.     $language = "Language: " . $record[11] . "<BR>";
  306.     }
  307.     if ($record[22] ne "")
  308.     {
  309.         $phone = "Phone:  " . $record[21] . $record[22];
  310.         $phone1 = $record[23] . $record[24];
  311.     }
  312.     if ($record[26] ne "")
  313.     {
  314.         $fax = "Fax:    " . $record[25] . $record[26];
  315.     }
  316.     if ($record[28] ne "")
  317.     {
  318.         $email = "Email:  " . $record[27] . $record[28];
  319.     }
  320.     if ($record[29] ne "")
  321.     {
  322.         $url = "Url:    " . $record[29];
  323.     }
  324.     $address =~ s/^//g;
  325.     $address1 =~ s/^//g;
  326.     $spec =~ s/\[//g;
  327.     $spec =~ s/]//g;
  328.     $spec =~ s/^ * //g;
  329.     $spec =~ s/^,//g;
  330.     if ($spec eq "")
  331.     {
  332.         $spec = "None.";
  333.     }
  334.  
  335.     if ($phone1 ne "")
  336.     {
  337.         $phone .= "\n        " . $phone1;
  338.     }
  339.  
  340.     if ($record[10] eq "t" or $record[10] eq "T")
  341.     {
  342.         $source = "Yes";
  343.     }
  344.     print PRODUCT <<MAKEPRODUCT
  345. <H3><A NAME=$record[4]>$record[4]</A></H3>
  346. <H4><A NAME=$record[5]>$record[5]</A></H4>
  347. $record[7]<p>
  348. $language
  349. Source Avail: $source<BR>
  350. Product Special Handling: $spec<BR>
  351. <HR>
  352. <PRE>
  353. <B>$record[5]</B>
  354. $address
  355. $address1
  356. $record[20]<HR>
  357. $phone
  358. $fax
  359. $email
  360. $url
  361. </PRE>
  362. MAKEPRODUCT
  363. }
  364.  
  365. #------------------------------------------------------------------
  366. # makeproducttail
  367. #
  368. # subroutine makeproducttail creates tail for product file
  369.  
  370. sub makeproducttail {
  371.  
  372.     print PRODUCT <<MAKEPRODUCTTAIL
  373. </body>
  374. </html>
  375. MAKEPRODUCTTAIL
  376. }
  377.  
  378. #------------------------------------------------------------------
  379. # makeTOCheader
  380. #
  381. # subroutine MakeTOCheader prints header for each TOC
  382.  
  383. sub makeTOCheader {
  384.  
  385.     local($filename) = @_[0];
  386.     local($category) = @_[1];
  387.     local($subcategory) = @_[2];
  388.  
  389.     print TOC <<makeTOCheader
  390. <html>
  391. <title>Solaris - <A HREF="$filename">$subcategory</A> Products</title>
  392.  
  393. <A HREF="http://$HOST/$HTML"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page </A>
  394. <A HREF="../$filename"><IMG SRC="/goto_back.gif"> Sub-category</A>
  395. <HR>
  396. <H1>Catalyst Solaris Products</H1>
  397. <H2>Product Listing</H2>
  398. <HR>
  399.  <h2><IMG SRC="/bullet_ball_red.gif"> <A HREF="../$filename">$subcategory</A></h2>
  400. <ul>
  401. makeTOCheader
  402. }
  403.  
  404. sub addsubTOCheader {
  405.  
  406.     local($category) = @_[0];
  407.  
  408.     print subTOC <<addsubTOCheader
  409. <title>Solaris - Networking</title>
  410.  
  411. <A HREF="http://$HOST/$HTML"><IMG SRC="/goto_toc.gif"> Catalyst Catalog Search Page</A>
  412. <HR>
  413. <H1>Catalyst Solaris Products</H1>
  414. <H2>Sub-categories</H2>
  415. <HR>
  416. <H2><IMG SRC="/bullet_ball_blue.gif"> $category<H2>
  417. <UL>
  418. addsubTOCheader
  419.  
  420. }
  421.  
  422. sub makeTOCtail {
  423.  
  424.     print subTOC <<makeTOCtail
  425. </ul></html>
  426. makeTOCtail
  427. }
  428.  
  429. sub addsubTOC {
  430.  
  431.     local($subcategory) = @_[0];
  432.     local($subcategoryname) = @_[1];
  433.  
  434.     print subTOC <<addsubTOC
  435. <IMG SRC="/bullet_ball_red.gif"><A HREF="$subcategoryname/$subcategoryname.html"><STRONG>  $subcategory</A></STRONG></A><BR>
  436. addsubTOC
  437. }
  438.  
  439. sub addTOCinfo {
  440.  
  441.         local($filename) = @_[0];
  442.         local($product) = @_[1];
  443.         local($vendor) = @_[2];
  444.  
  445.     print TOC <<addTOCinfo
  446. <B>
  447. <IMG SRC="/bullet_ball_yellow.gif"> <A HREF="$filename">$product</A></B>
  448. <ul>
  449. $vendor</ul><p>
  450. addTOCinfo
  451. }
  452.